package com.leyou.cart.controller;

import com.leyou.cart.pojo.Cart;
import com.leyou.cart.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("collect")
public class CollectController {

    @Autowired
    private CollectService collectService;

    //添加商品到我的收藏
    @PostMapping
    public ResponseEntity<Void> addCollect(@RequestBody Cart cart) {
        this.collectService.addCollect(cart);
        return ResponseEntity.ok().build();
    }

    //登录状态下查询收藏数据
    @GetMapping
    public ResponseEntity<List<Cart>> queryCollects() {
        //查询全部数据
        List<Cart> list = this.collectService.queryCollects();
        if (null == list || list.size() < 0) {
            return new ResponseEntity<>(HttpStatus.NO_CONTENT);
        }
        return ResponseEntity.ok(list);
    }

    //登录状态下删除收藏数据
    @DeleteMapping("{skuId}")
    public ResponseEntity<Void> deleteCollect(@PathVariable("skuId") String skuId) {
        //删除商品
        this.collectService.deleteCollect(skuId);
        return ResponseEntity.ok().build();
    }
}
